#include <iostream>
#include <vector>
using namespace std;

//二分法返回下标且按照对应的从小到大
int Search(vector<int>& nums, int target) {
  int isize_ = 0;
  int length_ = nums.size() - 1;
  int middle;
  while(isize_ <= length_) {
      middle = (isize_ + length_)/2;
      if (target == nums[middle]) {
          return middle;
      }
      if (target < nums[middle]) {
          length_ = middle - 1;
      }
      if (target > nums[middle]) {
          length_ = middle + 1;
      }
  }
  return -1;
}
//反转字符串,返回对应的反转字符串
//a.传入的是字符函数参数为vector<char>& Chars
//如:[‘h’,'l']===>['l',h']
vector<char> rev(vector<char>& Chars) {
//   for (int i = 0; i < Chars.size();i++) {
//     swap(Chars[i],Chars[Chars.size() - i - 1]);
//   }
  vector<char> test;
  for (int j = Chars.size(); j >= 0;j--) {
   test.push_back(Chars[j]);
  }
  return test;
}
// //二分法返回下标
// int Search(vector<int>& nums, int target) {
//   int isize_ = 0;
//   int length_ = nums.size() - 1;
//   int middle;
//   while(isize_ <= length_) {
//       middle = (isize_ + length_)/2;
//       if (target == nums[middle]) {
//           return middle;
//       }
//       if (target < nums[middle]) {
//           length_ = middle - 1;
//       }
//       if (target > nums[middle]) {
//           length_ = middle + 1;
//       }
//   }
//   return -1;
// }

int main() {
    vector<int> test;
    test.push_back(2);
    int target1 = 1;
    int search1 = Search(test,target1);
    cout << "search1 = " << search1 << endl;

    vector<int> test1;
    test1.push_back(2);
    int target2 = 2;
    int search2 = Search(test1,target2);
    cout << "search2 = " << search2 << endl;

    vector<int> test2;
    test2.push_back(2);
    test2.push_back(2);
    test2.push_back(3);
    test2.push_back(2);
    test2.push_back(1);
    int target3 = 1;
    int search3 = Search(test2,target3);
    cout << "search2 = " << search3 << endl;

   vector<char> tt;
   tt.push_back('1');
   tt.push_back('2');
   tt.push_back('a');
   tt.push_back('b');
   tt.push_back('c');
   vector<char> ttt = rev(tt);
   cout << "Char ttt: ";
   for (int i = 0;i < ttt.size();i++) {
       cout << ttt[i];
   }
   cout <<endl;

   vector<char> tts;
   tts.push_back('1');
   vector<char> ttts = rev(tts);
   cout << "Char ttts: ";
   for (int i = 0;i < ttts.size();i++) {
       cout << ttts[i];
   }
   cout <<endl;

   vector<char> ttss;
   ttss.push_back(' ');
   vector<char> tttss = rev(ttss);
   cout << "Char tttss: ";
   for (int i = 0;i < tttss.size();i++) {
       cout << tttss[i];
   }
   cout <<endl;
}
